﻿// 1018 锤子剪刀布.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//
#include <algorithm>
#include <iostream>
using namespace std;

int cwin1 = 0, cwin2 = 0, jwin1 = 0, jwin2 = 0, bwin1 = 0, bwin2 = 0;
int win1 = 0, even1 = 0, loss1 = 0;
int win2 = 0, even2 = 0, loss2 = 0;

void check(char a, char b) {
	if (a == 'C' && b == 'C') {
		even1++;
		even2++;
	}
	if (a == 'C' && b == 'J') {
		win1++;
		cwin1++;
		loss2++;
	}
	if (a == 'C' && b == 'B') {
		win2++;
		loss1++;
		bwin2++;
	}
	if (a == 'J' && b == 'C') {
		win2++;
		loss1++;
		cwin2++;
	}
	if (a == 'J' && b == 'J') {
		even1++;
		even2++;
	}
	if (a == 'J' && b == 'B') {
		win1++;
		jwin1++;
		loss2++;
	}
	if (a == 'B' && b == 'C') {
		win1++;
		loss2++;
		bwin1++;
	}
	if (a == 'B' && b == 'J') {
		win2++;
		loss1++;
		jwin2++;
	}
	if (a == 'B' && b == 'B') {
		even1++;
		even2++;
	}
}
int main()
{
	int n;
	cin >> n;
	char a, b;
	for (int i = 0; i < n; i++) {
		cin >> a >> b;
		check(a, b);
	}
	//胜平负
	cout << win1 << " " << even1 << " " << loss1 << endl;
	cout << win2 << " " << even2 << " " << loss2 << endl;
	int max1 = cwin1 > jwin1 ? cwin1 > bwin1 ? cwin1 : bwin1 : jwin1 > bwin1 ? jwin1 : bwin1;
	if (bwin1 == max1) {
		cout << "B ";
	}
	else if (cwin1 == max1) {
		cout << "C ";
	}
	else {
		cout << "J ";
	}
	int max2 = cwin2 > jwin2 ? cwin2 > bwin2 ? cwin2 : bwin2 : jwin2 > bwin2 ? jwin2 : bwin2;
	if (bwin2 == max2) {
		cout << "B";
	}
	else if (cwin2 == max2) {
		cout << "C";
	}
	else {
		cout << "J";
	}
	return 0;
}
